package leetcode.code0940;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	int mod = (int) 1e9 + 7;

	public int distinctSubseqII(String s) {
		char[] cs = s.toCharArray();
		boolean[] show = new boolean[26];
		long[] cnts = new long[cs.length];
		long ans = 0;
		for (int i = 0; i < cs.length; i++) {
			int c = cs[i] - 'a';
			long cur = 0;
			for (int j = i - 1; j >= 0; j--) {
				cur += cnts[j];
				if (cs[i] == cs[j]) {
					break;
				}
			}
			if (!show[c]) {
				show[c] = true;
				cur++;
			}
			cnts[i] = cur % mod;
			ans += cnts[i];
			ans %= mod;
		}
		return (int) ans;
	}

	@Override
	public void debug4() {
		H.compare(13, this.distinctSubseqII("cdce"));
		H.compare(3, this.distinctSubseqII("aaa"));
		H.compare(23, this.distinctSubseqII("abaaab"));
		H.compare(7, this.distinctSubseqII("abc"));
		H.compare(6, this.distinctSubseqII("aba"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
